home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / demos / c_gpc.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-08  |  2.0 KB  |  65 lines

  1. {
  2. GPC demo program to show how to include C code in Pascal programs.
  3.  
  4. Copyright (C) 2000-2001 Free Software Foundation, Inc.
  5.  
  6. Author: Frank Heckenbach <frank@pascal.gnu.de>
  7.  
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation, version 2.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; see the file COPYING. If not, write to
  19. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.
  21.  
  22. As a special exception, if you incorporate even large parts of the
  23. code of this demo program into another program with substantially
  24. different functionality, this does not cause the other program to
  25. be covered by the GNU General Public License. This exception does
  26. not however invalidate any other reasons why it might be covered
  27. by the GNU General Public License.
  28. }
  29.  
  30. program C_GPC;
  31.  
  32. { Link the C code. }
  33. {$L c_gpc_c.c}
  34.  
  35. { External declarations we use from the C code }
  36.  
  37. var
  38.   CVariable : Integer; asmname 'c_variable'; external;
  39.  
  40. procedure CRoutine; asmname 'c_routine';
  41.  
  42. { Pascal code }
  43.  
  44. var
  45.   PascalProgramVariable : Integer = 17; asmname 'pascal_program_variable';
  46.  
  47. procedure PascalProgramRoutine; asmname 'pascal_program_routine';
  48. procedure PascalProgramRoutine;
  49. begin
  50.   Writeln ('Routine in Pascal program called from C code.');
  51.   Writeln ('Decrementing CVariable.');
  52.   Dec (CVariable);
  53.   Flush (Output);
  54. end;
  55.  
  56. begin
  57.   Writeln ('Starting in the Pascal main program.');
  58.   Writeln ('PascalProgramVariable is ', PascalProgramVariable, '.');
  59.   Writeln ('Calling CRoutine.');
  60.   Flush (Output);
  61.   CRoutine;
  62.   Writeln ('Back in the Pascal main program.');
  63.   Writeln ('PascalProgramVariable is now ', PascalProgramVariable, '.')
  64. end.
  65.